package com.test;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;

public class SmsTemplateFillingInMemory {
    public static void main(String[] args) {
        Configuration cfg = new Configuration(Configuration.VERSION_2_3_31);
        try {
            String templateString = "尊敬的客户，您的订单编号为 ${orderNumber}，状态为 ${orderStatus}。";
            Template template = new Template("inMemoryTemplate", templateString, cfg);
            Map<String, Object> data = new HashMap<>();
            data.put("orderNumber", "123456");
            data.put("orderStatus", "已发货");
            StringWriter writer = new StringWriter();
            template.process(data, writer);
            String filledSms = writer.toString();
            System.out.println(filledSms);
        } catch (IOException | TemplateException e) {
            e.printStackTrace();
        }
    }
}
